package com.game.common.eventsystem;

import org.springframework.context.ApplicationContext;

public class GameEventSystem {
    // 初始化一个事件分发管理器
    private static final EventDispatchManager eventDispatchManager = new EventDispatchManager();
    private static final GameEventDispatchAnnotationManager gameEventDispatchAnnotationManager = new GameEventDispatchAnnotationManager();

    public static void start(ApplicationContext context) {
        gameEventDispatchAnnotationManager.init(context);
    }

    /**
     * 注册监听器
     * @param eventClass
     * @param listener
     */
    public static void registerListener(Class<? extends IGameEventMessage> eventClass, IGameEventListener listener) {
        eventDispatchManager.registerEventListener(eventClass, listener);
    }

    /**
     * 发送事件消息
     * @param origin
     * @param gameEventMessage
     */
    public static void sendGameEvent(Object origin, IGameEventMessage gameEventMessage) {
        eventDispatchManager.sendGameEvent(origin, gameEventMessage); // 向监听接口中发送事件
        gameEventDispatchAnnotationManager.sendGameEvent(gameEventMessage, origin); // 向注解中发送事件
    }
}
